<html xmlns:th="http://www.thymeleaf.org">
<footer   th:fragment="footer">
	 <!-- jQuery, Bootstrap, jQuery plugins and Custom JS code -->
        <script src="js/vendor/jquery-2.2.4.min.js"></script>
        <script src="js/vendor/bootstrap.min.js"></script>
        <script src="js/plugins.js"></script>
        <script src="js/app.js"></script>
        <script src="js/locales/bootstrap-datepicker.zh-CN.min.js"></script>
        <script src="js/locales/bootstrap-datetimepicker.zh-CN.js"></script>
        
        <!-- Load and execute javascript code used only in this page -->
        <script src="js/pages/uiTables.js"></script>
        <script src="js/pages/bootstable.js"></script>
        <script src="js/md5.js"></script>
        
        <script src="js/jquery.searchableSelect.js"></script>
        <script src="js/wangEditor.min.js"></script>
        <script src="js/sliderWip.js"></script>
        
        <script type="text/javascript">
       //礼物用于轮播的图片
        mockData=[
		      {
		        id:1,
		        img:'/img/vote/gift/allgifts/giftShow.png',
		      },
		      {
		        id:2,
		        img:'/img/vote/gift/allgifts/giftShow1.png',
		      },
		      {
		        id:3,
		        img:'/img/vote/gift/allgifts/giftShow2.png',
		      }, 
		      {
		        id:4,
		        img:'/img/vote/gift/allgifts/giftShow3.png',
		      }, 
		      {
		        id:5,
		        img:'/img/vote/gift/allgifts/giftShow4.png',
		      }, 
		     /*  {
			        id:3,
			        img:'/img/vote/gift/allgifts/giftShow2.png',
			      },  */
		    ]
        
        
        function changeTop(data){
        	$("#titletop").text();
        	$.ajax({
                url:"changeTop",
                type:"POST",
                dataType:'json',
                data:{"text":$(data).text()},
                success:function (data) {
                	
                }
            });
        }
        function flush(){
        	window.location.reload();
        }
        var showContent = function(obj){
        	$("#showContent").text($(obj).find("input").val());
        }
        $('.input-daterange').datepicker({
            "language":"zh-CN"
        });
        $('.input-datepicker').datepicker({
            "language":"zh-CN"
        });
        $('#mytable').SetEditable({
    		$addButton: $('#add')
    	});
        $('.input-datetimepicker').datetimepicker({
            language:'zh-CN',
            format: "yyyy-mm-dd",
            weekStart: 1,
            todayBtn:  1,
            autoclose: 1,
            todayHighlight: 1,
            startView: 2,
            minView: 2,
            forceParse: 0,
            showMeridian: 1
        });
        $('.input-datetimepicker2').datetimepicker({
            language:'zh-CN',
            format: "yyyy-mm-dd hh:ii",
            weekStart: 1,
            todayBtn:  1,
            autoclose: 1,
            todayHighlight: 1,
            startView: 2,
            minView: 0,
            forceParse: 0,
            showMeridian: 1
        });
        $('.input-datetimepicker3').datetimepicker({
            language:'zh-CN',
            format: "yyyy-mm",
            weekStart: 1,
            todayBtn:  1,
            autoclose: 1,
            todayHighlight: 1,
            startView: 3,
            minView: 3,
            forceParse: 0,
            showMeridian: 1
        });
        
      //子选择框全选了就选上总的没全选就去掉全选 
        var check_isall=function(){
        	var inputchecked=$("#general-table tbody tr td input[type='checkbox']:checked").length;
        	var totalinput=$("#general-table tbody tr td input[type='checkbox']").length;
        	if(totalinput>inputchecked){
        		$("#general-table thead tr th input[type='checkbox']").prop('checked',false);
        	}else{
        		$("#general-table thead tr th input[type='checkbox']").prop('checked',true);
        	}
        }
        //全选了就选中素有选择框全选去掉就去掉所有选择框  
        var choseall=function(){
        	if($("#general-table thead tr th input[type='checkbox']").is(':checked')){
        		$("#general-table tbody tr td input[type='checkbox']").prop('checked',true);
        	}else{
        		$("#general-table tbody tr td input[type='checkbox']").prop('checked',false);
        	}
        }
      //打开图片的原图信息
		var open_detail = function(thisobj){
		   window.open(thisobj.src);
		};
        var formatdate=function(time){
        	var myDate = new Date(time);   
        	           var YMD=myDate.getFullYear() + "-";
        	if(myDate.getMonth()+1<10){
        		YMD+="0"+(myDate.getMonth()+1)+ "-";
        	}else{
        		YMD+=(myDate.getMonth()+1)+ "-";
        	}
        	if(myDate.getDate()<10){
        		YMD+="0"+myDate.getDate();
        	}else{
        		YMD+=myDate.getDate();
        	}
/*         	           var HMS=myDate.getHours() + ":" + myDate.getMinutes() + ":" + myDate.getSeconds(); */
        	           var YMDHMS=YMD/* +" "+HMS */;
        	return YMDHMS;
        }
        var formatdate1=function(time){
        	/* alert(time) */
        	var myDate = new Date(time);
        	var Y=myDate.getFullYear() ;
        	var M=myDate.getMonth()+1;
        	var D=myDate.getDate();
        	var H=myDate.getHours();
        	var mm=myDate.getMinutes();
        	if(H<10){
        		H="0"+H;
        	}
        	if(mm<10){
        		mm="0"+mm;
        	}
        	return Y+"-"+M+"-"+D+" "+H+":"+mm;
        }
        var modifypass=function(){
        	var oldpass=$("#oldpass").val();
        	var newpass=$("#newpass").val();
        	var confirmpass=$("#confirmpass").val();
        	var reg = /^(?=.*[a-z]|.*[A-Z])(?=.*\d)[^]{6,16}$/;//(?=.*[A-Z])
        	if(newpass.length<6){
        		alert("密码长度需大于6位");
        		return;
        	}
	  	 	if (reg.test(newpass)){
	  			   /* $("#newpass").textbox("setValue", hex_md5(newpass));
	  			  $("#confirmpass").textbox("setValue", hex_md5(confirmpass)); */
	  			newpass=hex_md5(newpass);
	  			confirmpass=hex_md5(confirmpass);
	  	 	}else{
	  	 		alert("密码必须包含字母和数字");
        		return;
	  	 	}
        	$.ajax({
                url:"modifyPassword",
                type:"POST",
                data:{oldPassword:hex_md5(oldpass),newPassword:newpass,confirmpass:confirmpass},
                dataType:'json',
                success:function (data) {
                    if(data.status==1){
                    	window.location.href="i.do";
                    }else{
                    	alert(data.text);
                    }

                },
                error:function (e) {
                    console.log(e);
                }
                ,timeout:function (e) {
                    console.log(e);
                }
            }); 
        }
        $(function(){
        	console.log($(".sidebar-nav li.active "));
        });
        function serializeNotNull(serStr){
            // return serStr.split("&").filter(function(str){return !str.endsWith("=")}).join("&");
            return serStr.split("&").filter(str => !str.endsWith("=")).join("&");
        };
        var ajax_request_img=function(url,dataForm,redirectUrl){
        	$.ajax({
                url:url,
                type:"POST",
                data:dataForm,
                dataType:'json',
                contentType: false,
	            processData: false,
                success:function (data) {
                    if(data.status==1){
                    	if(url=="register"||url=="modifyUser"){
                    		alert(data.text);
                    	}
                    		window.location.href=redirectUrl;
                    }else{
                    	alert(data.text);
                    }

                },
                error:function (e) {
                    console.log(e);
                }
                ,timeout:function (e) {
                    console.log(e);
                }
            }); 
        };
        
        
        //权限联动
        var check_chose_power=function(obj){
      	   var id=$(obj).attr("id"); 
      	  var ischeck=$(obj).is(':checked');
      	  ischeck=!ischeck;
        	  if(id.indexOf("topLeave")>=0){
        			var idNo=id.replace("topLeave","");
        			 if(ischeck){//如果顶级表单是已经选中状态 那么下面所有的子选项都要清空
        			 var sobj=$("input[id=secondLeave"+idNo+"]:checked");
        			$("input[id=secondLeave"+idNo+"]:checked").prop('checked',false);
        			 for(var i=0;i<sobj.length;i++){
        				 var sl = sobj.eq(i).attr("name");
  					idNo=sl.replace("secondLeave","");
        				$("input[id="+idNo+"]:checked").prop('checked',false);
        			 }
        			 }
        			 return
               }
        		if(id.indexOf("secondLeave")>=0){
        			var idNo=id.replace("secondLeave","");
        			if(ischeck){//跳转表单如果是被选中状态 需要清空所有子选项
        				var slname = $(obj).attr("name");
        				var idNoname=slname.replace("secondLeave","");
        				$("input[id="+idNoname+"]:checked").prop('checked',false);
        			}else{//跳转表单如果是没有被选中状态那么顶级菜单需要同时被选中
        				$("#topLeave"+idNo).prop('checked',true);
        			}
        			return
              }  
          	  if(!ischeck){//如果操作权限是没有被选中状态
          		  $("input[name=secondLeave"+id+"]").prop('checked',true);
  	        	  var secondid=$("input[name=secondLeave"+id+"]").attr("id");
  	        	  var idtopneed=secondid.replace("secondLeave","")
          		 /*  $("#secondLeave"+id).prop('checked',true); */
          		  $("#topLeave"+idtopneed).prop('checked',true);
          	  }
          	  return 
        }
        
          var confirm_distribution=function(v){
          	var powerList=$("#session_power").val();
          	  var inputchecked=$("#power_replace input[type='checkbox']:checked")
          	 
            	var arrayid=new Array(inputchecked.length);
          	 var userId=$("#user_id").val();
          	var roleId=$("#role_id").val();
           	if(v==1){
           		roleId="";
          	  for(var p=0;p<inputchecked.length;p++){
          		  var row=inputchecked.eq(p).val();
          		  var  idsStr = userId+"-0-"+row;
          		  arrayid[p]=idsStr;
          	  }
           	}
           	if(v==2){
           		userId="";
           	 for(var p=0;p<inputchecked.length;p++){
         		  var row=inputchecked.eq(p).val();
         		  var  idsStr = "0-"+roleId+"-"+row;
         		  arrayid[p]=idsStr;
         	  }
           	}
          	 $.ajax({
          		 url:"addUserRoles",
          		 type:"post",
          		 data:{idsArry:arrayid+"",type:v,userid:userId,roleid:roleId},
          		 dataType:"json",
          		 success:function(data){
          			 if(data.status==1){
          				 if(v==1){
          					window.location.href="userAdmin?powerList="+powerList;
          				 }else if(v==2){
          					window.location.href="roleAdmin?powerList="+powerList;
          				 }
          				 
          			 }else{
          				 alert(data.text)
          				window.location.href="roleAdmin?powerList="+powerList;
          			 }
          		 },
          		 error:function (e) {
                       console.log(e);
                   }
                   ,timeout:function (e) {
                       console.log(e);
                   }
          	 })
          };
     </script>
    </footer>